package com.dqp.cslggroup.UI;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.dqp.cslggroup.R;

import java.util.List;

public class PupAdapter extends BaseAdapter {
    private String[] titles;
    private Context context;
    private List<Drawable> drawables;
    private int[] logos;
    private int select;

    //构造方法
    public PupAdapter(Context context, String[] titles, int[] logos) {
        this.context = context;
        this.titles = titles;
        this.logos = logos;
        select = 0;
    }

    //构造方法
    public PupAdapter(Context context, String[] titles, List<Drawable> drawables) {
        this.context = context;
        this.titles = titles;
        this.drawables = drawables;
        select = 1;
    }

    //获得数量
    public int getCount() {
        return titles.length;
    }

    //获得当前选项
    public Object getItem(int item) {
        return item;
    }

    //获得当前选项id
    public long getItemId(int id) {
        return id;
    }

    @Override

    //创建View方法
    public View getView(int position, View convertView, ViewGroup parent) {
        @SuppressLint("ViewHolder") View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.gridview_item, parent, false);
        TextView title = view.findViewById(R.id.menu_title);
        IconView logo = view.findViewById(R.id.menu_logo);
        title.setText(titles[position]);
        if (select == 1)
            logo.setBackground(drawables.get(position));
        else
            logo.setText(context.getResources().getString(logos[position]));
        return view;
    }

    @Override
    public void notifyDataSetChanged() {
        super.notifyDataSetChanged();
    }
}
